<?php
/***************************************************************************
 *
 *   copyright            : (C) 2011 Winds of Storm
 *
 *   $Id: urlfilter.php 131 2011-06-12 20:24:56Z stormerider $
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

$urlfilter	= array('TYPE'		=>	'filter',
			'NAME'		=>	'URL Filter',
			'VERSION'	=>	'0.0.1',
			'CREDIT'	=>	'StormeRider',
			'FUNC'		=>	'pluginURLFilter',
			'HELP'		=>	'pluginURLFilterHelp');
$plugins[]	= $urlfilter;

function pluginURLFilterHelp($help) {
	global	$urlfilter;

	$help['url2']	= array('url=[somemessage]:[someurl]',
				'Shows a chat-friendly link to [someurl] with the link text of [somemessage].' .
				pluginCredit($urlfilter));

	return $help;
}

function pluginURLFilter($msg) {
	global	$db;
	global	$dbprefix;

	// url=test:http://etc should translate to <a href=http://etc target=_blank>test</a>...

	if (eregi("url=([[:alnum:]]+):", $msg)) {
		$msg	= eregi_replace(
				"url=([[:alnum:]]+):([[:alnum:]]+)://([^[:space:]]*)([[:alnum:]#?/&=])",
				"<a href=\"\\2://\\3\\4\" target=\"_blank\">\\1</a>",
				$msg);
		//addToLog("URL Filtered message: $msg");
	}

	return $msg;
}
?>
